﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MallInteractiveMap.CMSWebClient.Common;
using MallInteractiveMap.CMSWebClient.Presenter;
using MallInteractiveMap.DTO;

namespace MallInteractiveMap.CMSWebClient.BasicView
{
    public partial class MallDetail : DetailBasePage<DTOMall>
    {
        private string LISTDDATA = "LISTDATAMallDetail";
        private MallPresenter _presenter;
        protected void Page_Load(object sender, EventArgs e)
        {
            _presenter = new MallPresenter();
            if (!IsPostBack)
            {
                PrepareView();
            }
        }

        private void PrepareView()
        {
            Session[this.LISTDDATA] = _presenter.GetMalls();
            BindGrid();    
        }


        /// <summary>
        /// Bind the data grid.
        /// </summary>
        private void BindGrid()
        {
            if (Session[this.LISTDDATA] == null)
            {
                return;
            }
            this.ViewData = Session[this.LISTDDATA] as List<DTOMall>;
            MallGrid.DataSource = this.ViewData;
            MallGrid.DataBind();
        }

        #region Grid related Events
        public void MallGrid_Sorting(object sender, GridViewSortEventArgs e)
        {
            if (Session[this.LISTDDATA] != null)
            {
                base.ViewData = Session[this.LISTDDATA] as List<DTOMall>;
                Session[this.LISTDDATA] = SortViewData(e.SortExpression);
                BindGrid();
            }
        }

        protected void MallGrid_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            MallGrid.PageIndex = e.NewPageIndex;
            BindGrid();
            MallGrid.SelectedIndex = -1;
        }
        #endregion
    }
}